package edu.uj.petri.model;

import edu.uj.util.Observed;
import java.io.Serializable;
import java.util.Collection;

/**
 * stores elements from model layer. As Observed, notifies subscribers
 * of every change.
 * @author Piotrek
 */
public abstract class Model implements Serializable, Observed {
    
    /** event code for Observed */
    public static final int CHANGED=3256;
    
    public abstract Matrix getIncidenceMatrix();
    
    /**
     * creates new place from this model. To add it, invoke {@link #addPlace}.
     */
    public abstract Place createPlace();
    
    /**
     * creates new transition from this model. To add it, invoke {@link #addTransition}.
     */
    public abstract Transition createTransition();
    
    /**
     * modifies from and to by adding arc to them, and returns new arc
     */
    public abstract NormalArc createNormalArc(Node from, Node to);
    
    /**
     * modifies from and to by adding arc to them, and returns new arc
     */
    public abstract InhibitorArc createInhibitorArc(Node from, Node to);
    
    
    public abstract void addPlace(Place place);
    
    public abstract void addTransition(Transition transition);
    
    public abstract void addArc(Arc arc);

    
    public abstract void deletePlace(Place place);
    
    public abstract void deleteTransition(Transition transition);
    
    public abstract void deleteArc(Arc arc);
    
    
    /** finds active transitions, remembers them and returns  */
    public abstract Collection<Transition> findActiveTransitions();
    
    /**
     * returns remembered active transitions. Use {@link #findActiveTransitions}
     * to get active transitions after change in model.
     */
    public abstract Collection<Transition>  getActiveTransitions();
    
    /**
     * returns reference to collection containing all transitions.
     * do not modify it!
     */
    public abstract Collection<Transition> getAllTransitions();
    
    /**
     * returns reference to collection containing all places.
     *
     */ 
    public abstract Collection<Place> getAllPlaces();
    
    /** deactivates all active transitions */
    public abstract void clearActiveTransitions();
    
    
    /** returns memento remembering current number of tokens in each place */
    public abstract Marking getMarking();
    
    /** restores given number of tokens in places */
    public abstract void applyMarking(Marking marking);
    
}
